package com.yukefms.jointpoint;

import com.yukefms.jointpoint.interfaces.Position;
import static com.yukefms.jointpoint.GeometryAdaptorForPointCalculator.* ;

/**
 * @Description  Geometry relations based on Gamera coordination, (X, Y, Z), wherein X is for Horizonal,
 *               Y is for vertical
 * @Author Ping
 * @Date 2021/7/16 11:43
 **/
public class GeometryRelations {
    /**
     * P1 stays above P2
     * @param p1
     * @param p2
     * @return
     */
    public static boolean isHorizonalAbove(Position p1, Position p2) {
         return p1.getY() - p2.getY() > TolerantEpsilon.MOVING_LENGTH_EPSILON ;
    }

    /**
     * P1 is under below P2
     * @param p1
     * @param p2
     * @return
     */
    public static boolean isHorizonalBelow(Position p1, Position p2) {
       // System.out.println("dist Y:" + (p2.getY() - p1.getY())) ;
        return p1.getY() < p2.getY()-TolerantEpsilon.MOVING_LENGTH_EPSILON ;
    }

    public static boolean isHorizonalBelow(Position p1, Position p2, double disTolerant) {
        return  p1.getY() < p2.getY() + disTolerant ;
    }

    public static boolean isFront(Position p1, Position p2) {
        return p1.getZ() < p2.getZ() - TolerantEpsilon.STATIC_LENGTH_EPSILON ;
    }
    public static boolean isFrontAtMoving(Position p1, Position p2) {
        return p1.getZ() < p2.getZ() - TolerantEpsilon.MOVING_LENGTH_EPSILON ;
    }

    public static boolean isFront(Position p1, Position p2,double disEpsilon) {
        return p1.getZ() < p2.getZ() - disEpsilon ;
    }

    public static boolean isFrontAtMost(Position p1, Position p2,double disEpsilon) {
        return (p1.getZ() < p2.getZ()) && (p1.getZ() > p2.getZ() - disEpsilon) ;
    }

    public static boolean isFrontByY(Position p1, Position p2) {
        return p1.getY() - p2.getY() < 0 ;
    }
    public static boolean isBehind(Position p1, Position p2) {
        return p1.getY() - p2.getY() > 0 ;
    }

    public static boolean increasedAtZ(Position p1, Position p2) {
      /*  System.out.println("dist Z:" + (p2.getZ() - p1.getZ())) ;*/
        return p2.getZ() - p1.getZ() > TolerantEpsilon.MOVING_LENGTH_EPSILON ;
    }

    public static boolean slowlyIncreasedAtZ(Position p1, Position p2) {
        /*  System.out.println("dist Z:" + (p2.getZ() - p1.getZ())) ;*/
        return p2.getZ() - p1.getZ() > TolerantEpsilon.CROSSING_MOVING_DOWN_EPSILON ;
    }
    /**
     * Same distance between (p1, p2) and (p3, p4)
     * @param p1
     * @param p2
     * @param p3
     * @param p4
     * @return
     */
    public static boolean sameDistance(Position p1, Position p2, Position p3, Position p4) {
        return Math.abs(distanceOfTwoPositions(p1, p2) - distanceOfTwoPositions(p3, p4)) <= TolerantEpsilon.LENGTH_EPSILON ;
    }



}
